package com.bkgy.jobs;

import com.bkgy.controller.qualityDaily.service.IQualitydailyPlankRepService;
import com.bkgy.controller.repOutput.service.IRepOutputService;
import com.bkgy.controller.repTcmThickWidth.service.IRepTcmThickWidthService;
import com.bkgy.controller.repTechFit.service.IRepTechFitService;
import com.bkgy.controller.tcmReport.service.IRepTcmOutputInfService;
import com.bkgy.controller.tcmReport.service.IRepTcmOutputPlanActService;
import com.bkgy.controller.tpdol3data.service.ITPdoL3Tcm2280Service;
import com.bkgy.util.DateUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 每日0点延后执行，防止数据延迟
 * 1.特种钢前一天的生产数据
 * 2.生成质量日报》汽车板生产情况前一天报表 QUALITYDAILY_PLANK_REP
 * 3.上一日影响产量，重焊、开卷、剪切 rep_tcm_output_inf表
 * 4.工艺指标合格率统计 REP_TECH_FIT
 * 5.钢种厚度宽度分析报表 REP_TCM_THICK_WIDTH
 * 6.更新产量报表年、月数据 REP_OUTPUT
 * 7.更新上一日废次降 REP_TCM_OUTPUT_PLAN_ACT
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class DayDelayJob {
    private final ITPdoL3Tcm2280Service tcm2280Service;
    private final IQualitydailyPlankRepService plankRepService;
    private final IRepTcmOutputInfService infService;
    private final IRepTechFitService techFitService;
    private final IRepTcmThickWidthService tcmThickWidthService;
    private final IRepOutputService repOutputService;
    private final IRepTcmOutputPlanActService repTcmService;

    public void exec() {
        //前一天日期
        Date yestoday = DateUtil.getBeforDate();
        //任务1：构建特种钢前一天生产情况报表。
        try {
            boolean res3 = tcm2280Service.buildSpecialSteel(yestoday);
            log.info(res3 ? "{}特种钢生产情况构建完毕" : "【注意】：{}特种钢生产情况失败", DateUtil.getDateToString(yestoday, "MM/dd"));
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

        //任务2：生成质量日报》汽车板生产情况前一天报表
        try {
            plankRepService.buildPlankRepJob(yestoday);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

        //任务3：上一日影响产量，重焊、开卷、剪切
        try {
            infService.buildInfOutputJob(yestoday);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

        //任务4：工艺指标合格率统计
        try{
            techFitService.buildSucRateJob(yestoday);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

        //任务5：钢种厚度宽度分析报表
        try{
            tcmThickWidthService.buildSteelGradeWidthThickJob(yestoday);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

        //任务6：更新产量报表年、月数据
        try{
            repOutputService.updateOutputYearMonthJob(yestoday);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

        //任务7：更新上一日废次降
        try{
            repTcmService.updateLastDayOutputJob(yestoday);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
}
